Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: #6087 Display specific error message for course slug collision (revision) #6168

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

ichandrasharma
Copy link

@ichandrasharma ichandrasharma commented Feb 1, 2025

What this PR does

(Revision)
Fixes #6087

This PR addresses the issue where a generic "Internal Server Error" message was displayed when a user attempted to change a course slug to one that already existed.

Screenshots

Before:

This is an error occurring not showing proper message only showing Internal Server Error
Screenshot (69)

Course titles can be identical for different organizations or institutions, but must be unique within the same organization or institution. This is because course titles are used to dynamically generate URLs (slugs), and duplicate titles within the same organization would create URL conflicts.
look: below
Screenshot (70)

After:

Showing proper message
Updated
Screenshot (75)
Screenshot (76)

@@ -321,6 +321,10 @@ const API = {
});

if (!response.ok) {
if (response.status === 422 || response.status === 400) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than special handling in JS, this should follow the pattern used elsewhere in the app where the message from the JSON error response shown, rather than a message that is part of frontend code.

See assignments_controller.rb for some examples of this pattern, or the PR that fixed another instance of this sort of issue: #1760

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ragesoss I've made the changes you can check them. Now, the backend dynamically returns JSON error responses in all supported languages based on the selected language. I’ve also updated the screenshots for your review. Let me know if you have any feedback!

@JiyaGupta-cs
Copy link
Contributor

JiyaGupta-cs commented Feb 8, 2025

Just a suggestion, Displaying the existing course slug as a clickable link opening that existing course in a new tab so that users can easily identify which course it is colliding with by clicking on it. This will enhance clarity and user experience.
What do you think?

@ichandrasharma
Copy link
Author

Just a suggestion, Displaying the existing course slug as a clickable link opening that existing course in a new tab so that users can easily identify which course it is colliding with by clicking on it. This will enhance clarity and user experience.
What do you think?

It can be implemented, but the primary goal is to provide a clear and accurate message so that the user can choose a different slug.

@@ -321,6 +321,11 @@ const API = {
});

if (!response.ok) {
if (response.status === 422 ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this part of the change necessary? For other errors where we display the backend message, the existing data flows work without special handling of a specific status.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A 422 response returns a JSON structure (data.errors) with a dynamically generated slug, while other responses return plain text. If special handle is not applied, it results in an empty object, failing to extract the error message and causing the default Sentry log error (e.g., "Sentry is not defined")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other cases that use this error message handling pattern don't require extra code for handling the specific status. Can you identify what is different about this, compared with (for example) #createRandomPeerAssignments? I'd like for the error handling flow to be as simple and uniform as possible, so that most errors rely on the same code pathways without introducing new frontend code for each new case that needs user-readable error messages.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if i remove special handle this happens it throws empty [] this becomes default message of sentry
Screenshot (78)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ragesoss The code is working perfectly after removing the special Handle logic and adding a try-catch block around Sentry.captureMessage to handle failures. Unnecessary if conditions have also been removed. Please let me know if you need any more refinements.

@@ -51,6 +51,11 @@ def update
ensure_passcode_set
UpdateCourseWorker.schedule_edits(course: @course, editing_user: current_user)
render json: { course: @course }
rescue Course::DuplicateCourseSlugError => e
message = I18n.t('courses.error.duplicate_slug', slug: e.slug)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not indented properly. I expect linting to fail.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ragesoss I have fixed the linting issues, ensuring proper formatting and readability. Let me know if you need any further improvements

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For your reference, I reviewed both files. I added an extra function to keep the lines within the 16-line limit, ensuring compliance with linting.
Screenshot (79)
Screenshot (80)

@ragesoss
Copy link
Member

It looks like a test broke because of this new validation. You likely need to make a slight adjustment to that test so that it doesn't trigger the duplicate slug error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error message from course slug collision does not explain the problem
3 participants